home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src-glut / glut_menu2.c < prev    next >
C/C++ Source or Header  |  1998-12-15  |  5KB  |  186 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994, 1997. */
  3.  
  4. /* This program is freely distributable without licensing fees
  5.    and is provided without guarantee or warrantee expressed or
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. /* glut_menu2.c implements the little used GLUT menu calls in
  9.    a distinct file from glut_menu.c for slim static linking. */
  10.  
  11. /* The Win32 GLUT file win32_menu.c completely re-implements all
  12.    the menuing functionality implemented.  This file is used only by
  13.    the X Window System version of GLUT. */
  14.  
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <stdio.h>
  18. #include <errno.h>
  19. #include <assert.h>
  20.  
  21. #include <X11/Xlib.h>
  22.  
  23. #include "glutint.h"
  24. #include "layerutil.h"
  25.  
  26. /* CENTRY */
  27. /* DEPRICATED, use glutMenuStatusFunc instead. */
  28. void APIENTRY 
  29. glutMenuStateFunc(GLUTmenuStateCB menuStateFunc)
  30. {
  31.   __glutMenuStatusFunc = (GLUTmenuStatusCB) menuStateFunc;
  32. }
  33.  
  34. void APIENTRY 
  35. glutMenuStatusFunc(GLUTmenuStatusCB menuStatusFunc)
  36. {
  37.   __glutMenuStatusFunc = menuStatusFunc;
  38. }
  39.  
  40. void APIENTRY 
  41. glutDestroyMenu(int menunum)
  42. {
  43.   GLUTmenu *menu = __glutGetMenuByNum(menunum);
  44.   GLUTmenuItem *item, *next;
  45.  
  46.   if (__glutMappedMenu)
  47.     __glutMenuModificationError();
  48.   assert(menu->id == menunum - 1);
  49.   XDestroySubwindows(__glutDisplay, menu->win);
  50.   XDestroyWindow(__glutDisplay, menu->win);
  51.   __glutMenuList[menunum - 1] = NULL;
  52.   /* free all menu entries */
  53.   item = menu->list;
  54.   while (item) {
  55.     assert(item->menu == menu);
  56.     next = item->next;
  57.     free(item->label);
  58.     free(item);
  59.     item = next;
  60.   }
  61.   if (__glutCurrentMenu == menu) {
  62.     __glutCurrentMenu = NULL;
  63.   }
  64.   free(menu);
  65. }
  66.  
  67. void APIENTRY 
  68. glutChangeToMenuEntry(int num, const char *label, int value)
  69. {
  70.   GLUTmenuItem *item;
  71.   int i;
  72.  
  73.   if (__glutMappedMenu)
  74.     __glutMenuModificationError();
  75.   i = __glutCurrentMenu->num;
  76.   item = __glutCurrentMenu->list;
  77.   while (item) {
  78.     if (i == num) {
  79.       if (item->isTrigger) {
  80.         /* If changing a submenu trigger to a menu entry, we
  81.            need to account for submenus.  */
  82.         item->menu->submenus--;
  83.       }
  84.       free(item->label);
  85.       __glutSetMenuItem(item, label, value, False);
  86.       return;
  87.     }
  88.     i--;
  89.     item = item->next;
  90.   }
  91.   __glutWarning("Current menu has no %d item.", num);
  92. }
  93.  
  94. void APIENTRY 
  95. glutChangeToSubMenu(int num, const char *label, int menu)
  96. {
  97.   GLUTmenuItem *item;
  98.   int i;
  99.  
  100.   if (__glutMappedMenu)
  101.     __glutMenuModificationError();
  102.   i = __glutCurrentMenu->num;
  103.   item = __glutCurrentMenu->list;
  104.   while (item) {
  105.     if (i == num) {
  106.       if (!item->isTrigger) {
  107.         /* If changing a menu entry to as submenu trigger, we
  108.            need to account for submenus.  */
  109.         item->menu->submenus++;
  110.       }
  111.       free(item->label);
  112.       __glutSetMenuItem(item, label, /* base 0 */ menu - 1, True);
  113.       return;
  114.     }
  115.     i--;
  116.     item = item->next;
  117.   }
  118.   __glutWarning("Current menu has no %d item.", num);
  119. }
  120.  
  121. void APIENTRY 
  122. glutRemoveMenuItem(int num)
  123. {
  124.   GLUTmenuItem *item, **prev, *remaining;
  125.   int pixwidth, i;
  126.  
  127.   if (__glutMappedMenu)
  128.     __glutMenuModificationError();
  129.   i = __glutCurrentMenu->num;
  130.   prev = &__glutCurrentMenu->list;
  131.   item = __glutCurrentMenu->list;
  132.   /* If menu item is removed, the menu's pixwidth may need to
  133.      be recomputed. */
  134.   pixwidth = 1;
  135.   while (item) {
  136.     if (i == num) {
  137.       /* If this menu item's pixwidth is as wide as the menu's
  138.          pixwidth, removing this menu item will necessitate
  139.          shrinking the menu's pixwidth. */
  140.       if (item->pixwidth >= __glutCurrentMenu->pixwidth) {
  141.         /* Continue recalculating menu pixwidth, first skipping
  142.            the removed item. */
  143.         remaining = item->next;
  144.         while (remaining) {
  145.           if (remaining->pixwidth > pixwidth) {
  146.             pixwidth = remaining->pixwidth;
  147.           }
  148.           remaining = remaining->next;
  149.         }
  150.         __glutCurrentMenu->pixwidth = pixwidth;
  151.       }
  152.       __glutCurrentMenu->num--;
  153.       __glutCurrentMenu->managed = False;
  154.  
  155.       /* Patch up menu's item list. */
  156.       *prev = item->next;
  157.  
  158.       free(item->label);
  159.       free(item);
  160.       return;
  161.     }
  162.     if (item->pixwidth > pixwidth) {
  163.       pixwidth = item->pixwidth;
  164.     }
  165.     i--;
  166.     prev = &item->next;
  167.     item = item->next;
  168.   }
  169.   __glutWarning("Current menu has no %d item.", num);
  170. }
  171.  
  172. void APIENTRY 
  173. glutDetachMenu(int button)
  174. {
  175.   if (__glutMappedMenu)
  176.     __glutMenuModificationError();
  177.   if (__glutCurrentWindow->menu[button] > 0) {
  178.     __glutCurrentWindow->buttonUses--;
  179.     __glutChangeWindowEventMask(ButtonPressMask | ButtonReleaseMask,
  180.       __glutCurrentWindow->buttonUses > 0);
  181.     __glutCurrentWindow->menu[button] = 0;
  182.   }
  183. }
  184.  
  185. /* ENDCENTRY */
  186.